import AsyncValidator from "@/common/validator";
export const validateTypeEnum = {
  string: `string`,
  number: `number`,
  boolean: `boolean`,
  method: `method`,
  regexp: `regexp`,
  integer: `integer`,
  float: `float`,
  array: `array`,
  object: `object`,
  enum: `enum`,
  date: `date`,
  url: `url`,
  hex: `hex`,
  email: `email`,
  any: `any`,
};

export const liValidateData = (rules, data) => {
  const validator = new AsyncValidator(rules);

  return new Promise((resolve, reject) => {
    validator.validate(data, (errors, _fields) => {
      if (errors) {
        reject(errors[0].message);
      } else {
        resolve(true);
      }
    });
  });
};
